package com.wanmait.zaisousuo.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.zaisousuo.mapper.QuestionMapper;
import com.wanmait.zaisousuo.pojo.Question;
import com.wanmait.zaisousuo.service.QuestionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/backstage/question")
public class QuestionController {
    @Resource
    private QuestionService questionService;

    @RequestMapping("list")
    public void list(String startTime,String endTime,Model model){
        if (startTime=="") startTime=null;
        if (endTime=="") endTime=null;
        List<Question> questions = questionService.findByTime(startTime,endTime);
        model.addAttribute("questions",questions);
    }

    @RequestMapping("show")
    public void show(Integer id,Model model){
        Question question = questionService.findById(id);
        model.addAttribute("question",question);
    }
    @RequestMapping("realDelete")
    @ResponseBody
    public void realDelete(Integer id){
        questionService.clearCache();//清除问答的cache
        questionService.realDelete(id);
    }

    @RequestMapping("updateDisabled")
    @ResponseBody
    public void updateDisabled(Integer id,boolean disabled){
        questionService.clearCache();//清除问答的cache
        questionService.updateDisabled(id,disabled);
    }

    @RequestMapping("deleteAll")
    @ResponseBody
    public void deleteAll(String ids){
        questionService.clearCache();//清除问答的cache
        questionService.delete(ids);
    }

    @RequestMapping("recoverAll")
    @ResponseBody
    public void recoverAll(String ids){
        questionService.clearCache();//清除问答的cache
        questionService.recover(ids);
    }
}
